package com.dream.tihai.common.log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * @author Valley
 * Created by Valley on 2022/9/19
 */
@Aspect
@Component
public class LogAspect {

    @Pointcut("@annotation(com.dream.tihai.common.log.LogTarget)")
    public void point(){}

    @Around("point()")
    public Object methodAround(ProceedingJoinPoint point){
        long start = System.currentTimeMillis();
        Object proceed = null;
        try {
            proceed = point.proceed();
        }catch (Throwable e){
            System.out.println("异常处理");
        }
        long time = System.currentTimeMillis() - start;
        System.out.println(point.getSignature()+" spent time is " + time + "ms");
        return proceed;
    }

}
